#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <string>
using namespace std;
long long t, x;
int main()
{
	scanf("%lld", &t);
	while (t--)
	{
		scanf("%lld", &x);
		vector<string> v;
		v.reserve(x);
		for (long long i = 0; i < x; i++)
		{
			string s;
			cin >> s;
			v.push_back(s);
		}
		long long count = 0;
		for (long long i = 0; i < x; i++)
		{
			for (long long j = 0; j < x; j++)
			{
				if (i != j && ((v[i][0] == v[j][0] && v[i][1] != v[j][1])
					|| (v[i][0] != v[j][0] && v[i][1] == v[j][1])))
					count++;
			}
		}
		printf("%lld\n", count / 2);
	}
	return 0;
}

